import { ref, reactive, onBeforeMount } from 'vue'
import { qualityResultPages } from '@/api/qualityResult/index.js'

import cache from '@/utils/cache.js'
import { constant } from 'lodash';
import { usePageStore } from '@/pinia/page.js'

const store = usePageStore()

const totalNum = ref(0)

const formData = reactive({
  pageNo: 1,
  pageSize: 10,
  startTime: '',
  endTime: '',
  durationStart: undefined,
  durationEnd: undefined,
  callType: null,
  userNumber: '',
  agentId: [],
  projectId: JSON.parse(cache.getLocalstorage('authInfo')).agencyId,
  qualityProject: ''
});

//分页
const resultList = async (params) => {
    const  res = await qualityResultPages(params)
    totalNum.value = res.data.totalCount
    return res.data.list
}

// 根据保存的查询条件渲染数据
const historyQuery = async () => {
  let params = store.queryResultParams
  formData.startTime = params.startTime
  formData.endTime = params.endTime
  formData.pageNo = 1
  formData.pageSize = 10
  formData.callType = params.callType
  formData.durationStart = params.durationStart
  formData.durationEnd = params.durationEnd
  formData.agentId = params.agentId
  formData.userNumber = params.userNumber
  formData.type = 0
  formData.qualityProject = params.qualityProject
  const  res = await qualityResultPages(formData)
  totalNum.value = res.data.totalCount
  return res.data.list
}

export {
  totalNum,
  formData,
  resultList,
  historyQuery
}
